<div class="hbox hbox-auto-xs hbox-auto-sm" ng-init="
    app.settings.asideFolded = false;
    app.settings.asideDock = false;">
    <!-- main -->
    <div class="col">
        <!-- main header -->


        <div class="bg-light lter b-b wrapper-md">
            <div class="row">
                <div class="col-sm-6 col-xs-12" ng-controller="ciVersionCtrl">
                    <h4 class="m-n font-thin h3 text-black">Jenkins任务模版管理</h4>
                    <span class="label"
                          style="margin-left: 5px; background-color: #00a8f3; color: white;">Version{{version.literalVersion}}</span>
                </div>
            </div>
        </div>
        <!-- / main header -->
        <div class="wrapper-md">
            <!-- toaster directive -->
            <toaster-container
                    toaster-options="{'position-class': 'toast-top-right', 'close-button':true}"></toaster-container>
            <!-- / toaster directive -->

            <div class="panel panel-default" ng-controller="templateCtrl">
                <div class="panel-body">
                    <form class="form-inline" role="form">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon">模版名称</span>
                                <input type="text" class="form-control" ng-model="queryName"
                                       placeholder="名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon">应用类型</span>
                                <select class="form-control" ng-model="queryAppType"
                                        ng-options="app.code as app.name for app in appType">
                                    <option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon">构建类型</span>
                                <select class="form-control" ng-model="queryCiType"
                                        ng-options="ci.code as ci.name for ci in ciType"
                                        required>
                                    <option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>


                        <div class="form-group">
                            <button type="button" class="btn btn-info" ng-click="doQuery()"><span
                                    class="glyphicon glyphicon-search"></span>搜索
                            </button>
                        </div>

                        <button type="button" class="btn btn-info" ng-click="reSet()"><span
                                class="glyphicon glyphicon-repeat"></span>重置
                        </button>

                        <button ng-if="contains(authPoint, '/ci/template/save')" type="button" class="btn btn-success" ng-click="addTemplate()"><span
                                class="glyphicon glyphicon-plus"></span>新增
                        </button>

                        <button ng-if="contains(authPoint, '/ci/template/save')" type="button" class="btn btn-success" ng-click="scanTemplate()"><span
                                class="icon icon-feed"></span>扫描
                        </button>
                    </form>
                    <div class="panel panel-default" style="margin-top: 5px;;">
                        <div>
                            <table class="table table-hover table-bordered table-striped">
                                <thead>
                                <tr>
                                    <td class="col-md-3">模版</td>
                                    <td>环境</td>
                                    <td>关联任务</td>
                                    <td class="col-md-2">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                <tr ng-repeat="item in pageData">
                                    <td>
                                        <b style="color: #777"
                                           uib-popover-html="item.content"
                                           popover-trigger="'mouseenter'">{{item.name}}</b>
                                        <embed ng-if="item.appType == 0" class="pull-right"
                                               src="img/simpleicons/java.svg" width="15" height="15"
                                               type="image/svg+xml"
                                               pluginspage="img/simpleicons/"></embed>
                                        <embed ng-if="item.appType == 1" class="pull-right"
                                               src="img/simpleicons/python.svg" width="15" height="15"
                                               type="image/svg+xml"
                                               pluginspage="img/simpleicons/"></embed>
                                        <embed ng-if="item.appType == 2" class="pull-right"
                                               src="img/simpleicons/apple.svg" width="15" height="15"
                                               type="image/svg+xml"
                                               pluginspage="img/simpleicons/"></embed>
                                        <embed ng-if="item.appType == 3" class="pull-right"
                                               src="img/simpleicons/android.svg" width="15" height="15"
                                               type="image/svg+xml"
                                               pluginspage="img/simpleicons/"></embed>
                                        <embed ng-if="item.appType == 4" class="pull-right"
                                               src="img/simpleicons/test.svg" width="15" height="15"
                                               type="image/svg+xml"
                                               pluginspage="img/simpleicons/"></embed>
                                        </br>
                                        <b style="color: #2e6da4">{{item.version}}</b>
                                        <b class="pull-right">版本Code</b>
                                        </br>
                                        <b style="color: #2e6da4">{{item.md5}}</b>
                                        <b class="pull-right">HASH</b>
                                        </br>
                                        <b style="color: #20a03f" ng-if="item.ciType == 0">CI+CD</b>
                                        <b style="color: #5bc0de" ng-if="item.ciType == 1">CI</b>
                                        <b class="pull-right">构建类型</b>
                                    </td>
                                    <td>
                                        <b style="color:{{item.env.color}}">{{item.env.name}}</b>
                                    </td>
                                    <td>
                                        <div class="col-md-12" ng-repeat="job in item.jobList">
                                                 <span style="background-color: #286090; color: white;"
                                                       uib-popover-html="job.content"
                                                       popover-trigger="'mouseenter'"
                                                       class="label">{{job.jobName}}</span>
                                            <span style="background-color: #20a03f; color: white;"
                                                  uib-popover-html="'构建任务'"
                                                  popover-trigger="'mouseenter'"
                                                  class="label">CI</span>

                                            <button ng-if="contains(authPoint, '/ci/template/save')" ng-click="updateTemplate(job.id,0)"
                                                    ng-show="item.name == job.jobTemplate && job.jobVersion != item.version"
                                                    class="btn btn-xs pull-right"
                                                    style="margin-left: 5px; background-color: #af5f00; color: white;">
                                                <span class="icon icon-cloud-upload"></span>升级
                                            </button>
                                        </div>

                                        <div class="col-md-12" ng-repeat="deployJob in item.deployJobList">
                                                 <span style="background-color: #286090; color: white;"
                                                       uib-popover-html="deployJob.content"
                                                       popover-trigger="'mouseenter'"
                                                       class="label">{{deployJob.deployJobName}}</span>
                                            <span style="background-color: #20a03f; color: white;"
                                                  uib-popover-html="'部署任务'"
                                                  popover-trigger="'mouseenter'"
                                                  class="label">CD</span>
                                            <button  ng-if="contains(authPoint, '/ci/template/save')"  ng-click="updateTemplate(deployJob.id,1)"
                                                    ng-show="item.name == deployJob.deployJobTemplate && deployJob.deployJobVersion != item.version"
                                                    class="btn btn-xs pull-right"
                                                    style="margin-left: 5px; background-color: #ff8700; color: white;">
                                                <span class="icon icon-cloud-upload"></span>升级
                                            </button>
                                        </div>

                                    </td>
                                    <td>
                                        <button ng-click="viewTemplate(item)"
                                                class="btn btn-xs"
                                                style="margin-left: 5px; background-color: #20a03f; color: white;">
                                            <span class="glyphicon glyphicon-search"></span>查看
                                        </button>
                                        <button ng-if="contains(authPoint, '/ci/template/save')" ng-click="editTemplate(item)"
                                                class="btn btn-xs"
                                                style="margin-left: 5px; background-color: #2e6da4; color: white;">
                                            <span class="glyphicon glyphicon-edit"></span>编辑
                                        </button>
                                        <button ng-if="contains(authPoint, '/ci/template/del')" ng-click="delTemplate(item)"
                                                class="btn btn-xs pull-right"
                                                style="background-color: red; color: white;">
                                            <span class="glyphicon glyphicon-remove"></span>删除
                                        </button>
                                    </td>
                                </tr>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td colspan="9">
                                        <ul style="margin: 0px; float: right;" uib-pagination
                                            total-items="totalItems" ng-model="currentPage"
                                            items-per-page="pageLength" max-size="10"
                                            ng-change="pageChanged()" previous-text="&lsaquo;"
                                            next-text="&rsaquo;"></ul>
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            </uib-tab>


        </div>
    </div>
    <!-- / main -->
</div>


<script type="text/ng-template" id="templateInfoModal">
    <div ng-include="'tpl/modal/ci/ci_template_info_modal.html'"></div>
</script>


<script type="text/ng-template" id="previewTemplateModal">
    <div ng-include="'tpl/modal/preview/preview_modal.html'"></div>
</script>
